//
//  GMTOurOrderModel.m
//  GMTMall
//
//  Created by  Mac on 2020/10/28.
//  Copyright © 2020 lay. All rights reserved.
//

#import "GMTOurOrderModel.h"
#import "OrderGoodsEntityList.h"

@implementation StoreBtnsModel
-(instancetype)initWithTitle:(NSString * )title andColor:(UIColor *)titleColor andClickType:(OurOrderBlockType)clickType {
 self = [super init];
    if (self) {
        _title = title;
        _color = titleColor;
        _clickType = clickType;
    }
    return self;
}
@end

@implementation GMTOurOrderModel

+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{ @"ID" : @"id"};
}

-(void)setGoodsName:(NSString *)goodsName {
    _goodsName = goodsName;
    CGFloat contentLabelWidth = SCREEN_WIDTH - 90 - 8 - 60 - 8 - 26 - 20;
    CGRect re = [goodsName boundingRectWithSize:CGSizeMake(contentLabelWidth, 48) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:UIFontBoldMake(13)} context:nil];
    CGFloat contentLabelHeight = re.size.height > 40 ? 40 : re.size.height;
    CGRect contentRect = CGRectMake(78, 28, contentLabelWidth,contentLabelHeight);
    _contentRect = contentRect;
}

+(NSDictionary *)mj_objectClassInArray {
    return @{@"orderGoodsEntityList":[OrderGoodsEntityList class]};
}

+(instancetype)mj_objectWithKeyValues:(id)keyValues context:(NSManagedObjectContext *)context {
    if ([keyValues objectForKey:@"orderEntityList"]) {
        NSDictionary * dic = [[NSArray arrayWithArray:keyValues[@"orderEntityList"]] firstObject];
        GMTOurOrderModel * model = [[[GMTOurOrderModel alloc] mj_setKeyValues:dic] mj_setKeyValues:keyValues];
        return model;
    }else {
        return  [super mj_objectWithKeyValues:keyValues context:context];
    }
}

- (NSArray *)btnsArr {
    if (_btnsArr) {
        return _btnsArr;
    }
    NSMutableArray * arr = [NSMutableArray arrayWithCapacity:0];
    NSInteger  orderStatus =  self.orderStatus;
    NSInteger payStatus = self.payStatus;
    NSInteger shippingStatus = self.shippingStatus;
    NSString * refundTime = self.refundTime;
     
     switch (orderStatus) {
         case 0:{
             StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"关闭订单" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_CloseOrder];
             [arr addObject:model1];
             StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"去支付" andColor:GMTRedColor andClickType:GMTOurStoreAction_Pay];
             [arr addObject:model2];
         }
             break;
         case 201:{
             if (payStatus == 3) {
                 StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"申请退款" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_RefundMoney];
                 [arr addObject:model1];
             }else if (payStatus == 4){
                 StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"等待退款" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_WaitBackMoney];
                 [arr addObject:model1];
             }
         }
             break;
         case 300:{
             StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"申请退款" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_RefundMoney];
             [arr addObject:model1];
             StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"确认收货" andColor:GMTBlueColor andClickType:GMTOurStoreAction_ReceiptGoods];
             [arr addObject:model2];
             if (refundTime.isNotBlankString) {
                 StoreBtnsModel * model3 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
                 [arr addObject:model3];
             }
         }
             break;
         case 301:{
             StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"再次购买" andColor:GMTBlueColor andClickType:GMTOurStoreAction_BuyAgain];
             [arr addObject:model1];
             if (refundTime.isNotBlankString) {
                 StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
                 [arr addObject:model2];
             }
         }
             break;
         case 401:{
             if (payStatus == 4) {
                 StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"已退款" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_DidBackMoney];
                 [arr addObject:model1];
                 StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
                 [arr addObject:model2];
             }
         }
             break;
         case 400:{
             StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
             [arr addObject:model1];
             if (shippingStatus == 2) {
                 StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"确认收货" andColor:GMTBlueColor andClickType:GMTOurStoreAction_ReceiptGoods];
                 [arr addObject:model2];
             }
         }
             break;
         case 403:{
             if (payStatus == 3) {
                 if (shippingStatus == 2) {
                     StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"申请退款" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_RefundMoney];
                     [arr addObject:model1];
                     StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"确认收货" andColor:GMTBlueColor andClickType:GMTOurStoreAction_ReceiptGoods];
                     [arr addObject:model2];
                     StoreBtnsModel * model3 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
                     [arr addObject:model3];
                 }else if (shippingStatus == 3){
                     StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"再次购买" andColor:GMTBlueColor andClickType:GMTOurStoreAction_BuyAgain];
                     [arr addObject:model2];
                     StoreBtnsModel * model3 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
                     [arr addObject:model3];
                 }else if (shippingStatus == 4){
                     StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"已退款" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_DidBackMoney];
                     [arr addObject:model1];
                 }else if (shippingStatus == 1){
                     StoreBtnsModel * model1 = [[StoreBtnsModel alloc] initWithTitle:@"申请退款" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_RefundMoney];
                     [arr addObject:model1];
                     StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
                     [arr addObject:model2];
                 }
             }else {
                 StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
                 [arr addObject:model2];
             }
         }
             break;
         case 402: {
             StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
             [arr addObject:model2];
         }
             break;
         case 405:
         case 406:{
             StoreBtnsModel * model2 = [[StoreBtnsModel alloc] initWithTitle:@"售后详情" andColor:GMTDarkGrayColor andClickType:GMTOurStoreAction_AfterSale];
             [arr addObject:model2];
         }
             break;
         default:{
         }
             break;
     }
    return arr;
}

- (NSString *)title {
    if (_title.isNotBlankString) {
        return _title;
    }
    NSInteger orderStatus =  self.orderStatus;
    NSInteger payStatus = self.payStatus;
    NSString * tittle;
      switch (orderStatus) {
          case 0:
              tittle = @"待付款";
              break;
          case 201:
              tittle = @"待发货";
              break;
          case 300:
              tittle = @"待收货";
              break;
          case 301:
              tittle = @"已完成";
              break;
          case 401:{
              if (payStatus == 4) {
                  tittle = @"已退款";
              }
          }
              break;
          case 400:{
              tittle = @"退款审核中";
          }
              break;
          case 403:{
              tittle = @"申请退款被拒";
          }
              break;
          case 405:{
              tittle = @"退款成功";
          }
              break;
          case 406:{
              tittle = @"退款失败";
          }
              break;
          default:
              break;
      }
    return tittle;
}


@end

